package com.aaa.service.impl;

import com.aaa.dao.UsersDao;
import com.aaa.entity.Users;
import com.aaa.service.UsersService;
import com.aaa.util.DefaultMsg;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UsersServiceImpl extends ServiceImpl<UsersDao, Users> implements UsersService {

    @Resource
    private UsersDao usersDao;
    @Override
    public DefaultMsg checkUser(Users user) {
        DefaultMsg defaultMsg=new DefaultMsg();
        //根据用户名查询用户的密码
        Users dbUser=usersDao.findByUsername(user.getUsername());
        //判断如果dbUser为null
        if (dbUser==null){
            defaultMsg.setSuccess(0);
            defaultMsg.setError("用户名或者密码错误");
            return defaultMsg;
        }
        //获取数据库中的用户密码
        String dbPassword= dbUser.getPassword();
        //比较用户传递过来的密码和数据库中的密码是否相等
        //我们关注  不相等
        if (!dbPassword.equals(user.getPassword())){
            defaultMsg.setSuccess(0);
            defaultMsg.setError("用户名或者密码错误");
        }
        defaultMsg.setTarget(dbUser);
        return defaultMsg;
    }
}
